package com.ai.bitcoin.jpa.dao;

import com.ai.bitcoin.jpa.entity.BccNews;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author Jason
 * @date 2018.5.13
 **/
public interface BccNewsDao extends JpaRepository<BccNews, String> {
    List<BccNews> findByBatchNo(String batchNo);

    List<BccNews> findByBatchNo(String batchNo, Pageable pageable);

    Page<BccNews> findAll(Pageable pageable);

    @Query(nativeQuery = true, value = "\n" +
            "SELECT \n" +
            " * " +
            "FROM  bcc_news_info_crawl\n" +
            "where id in (SELECT news_id FROM coin_news2bcc WHERE bcc_id = ?1 and to_days(update_time) = to_days(now()))")
    List<BccNews> queryCurrentNewsByBccId(String bccId);


    @Query(nativeQuery = true, value = "select * from bcc_news_info_crawl where id in (?1) ")
    List<BccNews> queryByNewsIdIn(List<String> newsId);
}
